package com.baizhi.util;

import com.baizhi.dao.CmfzResourceDao;
import com.baizhi.entity.CmfzResource;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.util.List;

public class ResourceUtil {

    public static void getParentResource(List<CmfzResource> pList, CmfzResourceDao cmfzResourceDao){
        for (CmfzResource p:pList) {
            // 封装资源
            selectSonResource(p,cmfzResourceDao);
        }
    }

    /**
     * 不确定节点资源封装
     * @param resource
     */
    public static void selectSonResource(CmfzResource resource,CmfzResourceDao resourceDao){
        // 根据父节点查询子节点
        List<CmfzResource> sonList = resourceDao.selectList(new QueryWrapper<CmfzResource>().eq("resource_parent_id",resource.getResourceId()));
        // 判断子资源是否存在，如果存在，继续查询子子资源
        if(sonList.size()>0 || null !=sonList){
            // 将子资源 放入父级集合属性中
            resource.setChildrens(sonList);

            getParentResource(sonList,resourceDao);
        }
    }

}
